// src/services/scholarsDashboardService/scholarPerformanceReport.ts

import { BASE_URL } from '@/services/apiConfig';

const exportScholarPerformanceReport = async (cocode: string) => {
  const token = localStorage.getItem('token');
  if (!token) throw new Error('No token found');

  const query = new URLSearchParams();
  if (cocode) query.append('query', cocode);

  const res = await fetch(`${BASE_URL}/scholars/export-performance-report?${query.toString()}`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${token}`,
    },
  });

  if (!res.ok) {
    const err = await res.text();
    throw new Error(`Export failed: ${res.status} - ${err}`);
  }

  const blob = await res.blob();
  return blob;
};

export { exportScholarPerformanceReport };